Feeling

Feelings Table

Feelings at time of assessment

Feeling Strongly Disagree Disagree Neutral Agree Strongly Agree
Happy 310 (4%) 698 (9%) 2558 (32%) 3210 (40%) 1333 (16%)
Frustrated 1526 (19%) 3326 (41%) 1704 (21%) 1165 (14%) 388 (5%)
Sad 1647 (20%) 3889 (48%) 1548 (19%) 697 (9%) 328 (4%)
Worried 1482 (18%) 3064 (38%) 1711 (21%) 1412 (17%) 440 (5%)
Restless 1435 (18%) 3113 (38%) 1892 (23%) 1384 (17%) 285 (4%)
Excited 511 (6%) 2078 (26%) 3085 (38%) 1519 (19%) 916 (11%)
Calm 298 (4%) 1034 (13%) 2762 (34%) 2998 (37%) 1017 (13%)
Lonely 1757 (22%) 3297 (41%) 1732 (21%) 753 (9%) 570 (7%)
Bored 1750 (22%) 3450 (43%) 1928 (24%) 758 (9%) 223 (3%)
Sluggish 1422 (18%) 2665 (33%) 1751 (22%) 1573 (19%) 698 (9%)

Feelings Charts

Location

Location Table

Location at time of assessment

Location No Yes
Bus, Train, or Vehicle 7554 (93%) 555 (7%)
Church 7936 (98%) 173 (2%)
Home 2071 (26%) 6038 (74%)
Friend’s or Relative’s House 7642 (94%) 467 (6%)
Store / Mall 7960 (98%) 149 (2%)
Outdoors 7401 (91%) 708 (9%)
Other 7613 (94%) 496 (6%)
Restaurant 8068 (99%) 41 (1%)
School / Library 8109 (100%) 0 (0%)
Work 7977 (98%) 132 (2%)

Location Charts

Activity

Activity Table

Activity at time of assessment

Activity No Yes
Interacting With Someone 5893 (73%) 2216 (27%)
Sitting 4086 (50%) 4023 (50%)
Sleeping 6375 (79%) 1734 (21%)
Standing 6926 (85%) 1183 (15%)
Walking / Excercising 7454 (92%) 655 (8%)
Talking 6482 (80%) 1627 (20%)
Other 6631 (82%) 1478 (18%)

Activity Charts

Physical Activity

Table Row

Physical activity yesterday (Yes / No)

Activity No Yes
Walked or Biked to Get Somewhere 4777 (59%) 3332 (41%)
Engaged in Physical Fitness 6874 (85%) 1235 (15%)
Engaged in Physical Activity at Work or Home 4076 (50%) 4033 (50%)
Did None of These 5979 (74%) 2130 (26%)
Used Pedometer 7791 (96%) 318 (4%)

Physical activity yesterday (Minutes)

Activity 10 Minutes or Less 11-20 Minutes 21-30 Minutes 31-40 Minutes 41-50 Minutes More than 50 Minutes
Walked or Biked to Get Somewhere 285 (9%) 654 (20%) 881 (26%) 639 (19%) 308 (9%) 565 (17%)
Engaged in Physical Fitness 37 (3%) 134 (11%) 254 (21%) 278 (23%) 231 (19%) 301 (24%)
Engaged in Physical Activity at Work or Home 205 (5%) 406 (10%) 856 (21%) 942 (23%) 592 (15%) 1033 (26%)

Sitting time yesterday

Variable 4 or Fewer Hours More than 4 Hours- 6 Hours More than 6 Hours- 8 Hours More than 8 Hours- 10 Hours More than 10 Hours - 12 Hours More than 12 Hours
Sitting Time Yesterday 2235 (28%) 2079 (26%) 1621 (20%) 1281 (16%) 480 (6%) 413 (5%)

Physical Activity Charts

Diet

Table Row

Ate any yesterday (Yes / No)

Food No Yes
Fruit 2737 (34%) 5372 (66%)
Vegetables 1835 (23%) 6274 (77%)
Sugar-Sweetened Beverages 2669 (33%) 5440 (67%)
Deserts and Other Sweets 3596 (44%) 4513 (56%)
Red Meat or Processed Meat 2500 (31%) 5609 (69%)

Servings ate yesterday

Food 0 Servings 1 Serving 2 Servings 3 Servings 4 Servings 5 or More Servings
Fruit 2737 (34%) 2419 (30%) 1759 (22%) 859 (11%) 196 (2%) 139 (2%)
Vegetables 1835 (23%) 2662 (33%) 2299 (28%) 958 (12%) 217 (3%) 138 (2%)
Sugar-Sweetened Beverages 2669 (33%) 1862 (23%) 1406 (17%) 1149 (14%) 383 (5%) 640 (8%)
Deserts and Other Sweets 3596 (44%) 2579 (32%) 1211 (15%) 527 (6%) 145 (2%) 51 (1%)
Red Meat or Processed Meat 2500 (31%) 2495 (31%) 2284 (28%) 702 (9%) 95 (1%) 33 (0%)

Diet Charts

Medication

Medication Table

Did you take all your medication as prescribed yesterday, and if not, which ones didn’t you take?

Medication No Yes
Take Medications 719 (9%) 7388 (91%)
Didn’t Take Depression / Anxiety / Mood Medication 7679 (95%) 430 (5%)
Didn’t Take Psychiatric Medication 7924 (98%) 185 (2%)
Didn’t Take Asthma / COPD Medication 8037 (99%) 72 (1%)
Didn’t Take Blood Pressure Medication 7930 (98%) 179 (2%)
Didn’t Take Diabetes Medication 7979 (98%) 130 (2%)
Didn’t Take Pain Medication 7990 (99%) 119 (1%)
Didn’t Take Cholesterol Medication 7964 (98%) 145 (2%)
Didn’t Take Antibiotic / Antiviral Medication 8081 (100%) 28 (0%)
Didn’t Take Other Medication 7910 (98%) 199 (2%)

Why didn’t you take medications?

Reason Wasn’t a Reason Was a Reason
Ran out 7771 (96%) 338 (4%)
Forgot 8012 (99%) 97 (1%)
Don’t Need It 8096 (100%) 13 (0%)
Side Effects 8000 (99%) 109 (1%)
Got Lost / Stolen 8098 (100%) 11 (0%)
Other 7899 (97%) 210 (3%)

Medication Charts

Freetime

Freetime Table

How much free time did you have yesterday?

Free time 2 or fewer hours More than 2 hours- 4 hours More than 4 hours- 6 hours More than 6 hours- 8 hours More than 8 hours- 10 hours More than 10 hours
Amount 1096 (14%) 1509 (19%) 1783 (22%) 1447 (18%) 1039 (13%) 1233 (15%)

What did you do in your free time yesterday?

Activity Didn’t Do Yesterday Did Yesterday
Watched TV 1275 (16%) 6834 (84%)
Played Computer Games 8109 (100%) 0 (0%)
Went to a Movie 8109 (100%) 0 (0%)
Surfed the Internet 4204 (52%) 3905 (48%)
Read 6058 (75%) 2051 (25%)
Listened to Music or Played Instrument 5792 (71%) 2317 (29%)
Arts and Crafts 6867 (85%) 1242 (15%)
Cleaned 4440 (55%) 3669 (45%)
Took Care of Pets 6582 (81%) 1527 (19%)
Prayed, Meditated, or Went to Religious Service 5542 (68%) 2567 (32%)
Played a Sport 7961 (98%) 148 (2%)
Walk or Jog 6776 (84%) 1333 (16%)
Played Cards, Dice, or Board Games 8109 (100%) 0 (0%)
Went Shopping 6806 (84%) 1303 (16%)
Volunteered 7213 (89%) 896 (11%)
Socialized 5154 (64%) 2955 (36%)
None of These 7891 (97%) 218 (3%)

Freetime Charts

Interaction

Interaction Table

Any meaningful interaction yesterday

Type No Yes
One-On-One Conversations 1563 (19%) 6542 (81%)
Group Interactions 4094 (51%) 4011 (49%)

Amount of meaningful interaction yesterday

Type 15 or Fewer Minutes 16-30 Minutes 31 min- 1 Hour More than 1 Hour- 2 Hours More than 2 Hours- 3 Hours More than 3 Hours- 4 Hours More than 4 Hours
One-On-One Conversations 1563 (19%) 1205 (15%) 1681 (21%) 1604 (20%) 1087 (13%) 391 (5%) 574 (7%)
Group Interactions 4094 (51%) 1014 (13%) 1206 (15%) 1104 (14%) 523 (6%) 48 (1%) 116 (1%)

Interaction Charts

Substances

Substances Tables

Substances used yesterday

Type No Yes
Alcohol 7543 (93%) 566 (7%)
5 or More Alcoholic Drinks 524 (92%) 44 (8%)
Tobacco 4747 (59%) 3362 (41%)
Marijuana 7568 (93%) 541 (7%)
Opiates 7666 (95%) 443 (5%)
Stimulants 8080 (100%) 29 (0%)
Herbal Drugs / Incense 8100 (100%) 9 (0%)
Another drug 8109 (100%) 0 (0%)
None 4209 (52%) 3900 (48%)

Substances Charts

Session Info

R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.4 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dataclean_0.1.0     ggplot2_2.1.0       tidyr_0.4.1        
[4] knitr_1.13          dplyr_0.5.0         flexdashboard_0.2.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.5      magrittr_1.5     munsell_0.4.3    colorspace_1.2-6
 [5] R6_2.1.2         highr_0.6        stringr_1.0.0    plyr_1.8.4      
 [9] tools_3.3.1      grid_3.3.1       gtable_0.2.0     DBI_0.4-1       
[13] htmltools_0.3.5  lazyeval_0.2.0   yaml_2.1.13      assertthat_0.1  
[17] digest_0.6.9     tibble_1.1       formatR_1.4      evaluate_0.9    
[21] rmarkdown_0.9.6  labeling_0.3     stringi_1.1.1    scales_0.4.0    
[25] jsonlite_0.9.20 
---
title: "Exploratory Analysis of Daily EMA Data"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: scroll
    source: embed
---

```{r setup, include=FALSE}
# Setup options
knitr::opts_chunk$set(collapse = TRUE, comment = "")

# CRAN packages
library(flexdashboard)
library(dplyr)
library(knitr)
library(tidyr)
library(ggplot2)

# devtools::install_github("mbcann01/dataclean")
library(dataclean)

# Load ea_kable
source("/Users/bradcannell/Dropbox/Research/mChat/R scripts/ea_kable.R")

# Load data
load("/Users/bradcannell/Dropbox/Research/mChat/data/daily_ema.RData")

# Sort by case number and date
daily <- dplyr::arrange(daily, case_number, date)
```

Overview {.sidebar data-width=300}
===============================================================================

Here we plot the aggregate unconditional distribution of responses for each of the following variables:

1. Feelings at time of assessment

2. Location at time of assessment

3. Activity at time of assessment

4. Physical activity yesterday

5. Diet yesterday

6. Medication use yesterday

7. Freetime activities yesterday

8. Meaningful Interaction yesterday

9. Substance use yesterday

```{r overview}
obs          <- nrow(daily)
vars         <- ncol(daily)
subj         <- length(base::unique(daily$case_number))
n_per_subj   <- count(daily, case_number)
avg_per_subj <- round(mean(n_per_subj$n), 0)
max_n_subj   <- max(n_per_subj$n)
min_n_subj   <- min(n_per_subj$n)
  

cat(paste("The dataset contains: \n", 
  obs, "Observations \n",
  vars, "Variables \n",
  subj, "Unique participants \n",
  "With an average of", avg_per_subj, "\n", "observations each \n",
  "Max =", max_n_subj, "observations \n",
  "Min =", min_n_subj, "observation")
)
```





Feeling
===============================================================================

Feelings Table
-------------------------------------------------------------------------------

### Feelings at time of assessment

```{r feeling_table}
feelings <- select(daily, happy:sluggish)

vars <- tools::toTitleCase(names(feelings))

ea_kable(
  x = feelings, 
  xlab = vars, 
  nrows = 10, 
  ncols = 6, 
  colnames = c("Feeling", "Strongly Disagree", "Disagree", "Neutral", "Agree", 
    "Strongly Agree")
) 
```

Feelings Charts
-------------------------------------------------------------------------------

```{r plot_emotions}
for (var in vars) {
  plot <- ggplot(daily, aes_string(x = tolower(var))) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("I Feel", var, "Right Now")) +
    theme_bw()
  print(plot)
}
```









Location
===============================================================================

Location Table
-------------------------------------------------------------------------------

### Location at time of assessment

```{r location_table}
x <- select(daily, loc_bus:loc_work)

loc <- c("Bus, Train, or Vehicle", "Church", "Home", "Friend's or Relative's House", "Store / Mall", "Outdoors", "Other", "Restaurant", "School / Library", "Work")

ea_kable(
  x = x, 
  xlab = loc, 
  nrows = 10, 
  ncols = 3, 
  colnames = c("Location", "No", "Yes")
)
```

Location Charts
-------------------------------------------------------------------------------

```{r plot_location, fig.width=12}
# Summarize
x <- data.frame(sapply(x, table))

# Tidy data
x <- gather(x)

# Keep even numbered rows
x <- x[c(FALSE, TRUE), ]

# Improve readability
x$key <- loc

# Plot the data
ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Location at Time of Assessment") +
  theme_bw()
```









Activity
===============================================================================

Activity Table
-------------------------------------------------------------------------------

### Activity at time of assessment

```{r activity_table}
x <- select(daily, pre_who, act_sit:act_talk, act_other)

act <- c("Interacting With Someone", "Sitting", "Sleeping", "Standing", "Walking / Excercising", "Talking", "Other")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 7, 
  ncols = 3, 
  colnames = c("Activity", "No", "Yes")
)
```

Activity Charts
-------------------------------------------------------------------------------

```{r plot_act, fig.width=12}
x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- act

# Plot the data
ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Activity Immediately Prior to Assessment") +
  theme_bw()
```









Physical Activity
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Physical activity yesterday (Yes / No)

```{r physact_table_1}
x <- select(daily, yest_bike, yest_run, yest_cleaning, yest_none, pedometer)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 5, 
  ncols = 3, 
  colnames = c("Activity", "No", "Yes")
)
```

### Physical activity yesterday (Minutes)

```{r physact_table_2}
x <- select(daily, min_walk, min_run, min_act)

act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home")

ea_kable(
  x = x, 
  xlab = act, 
  nrows = 3, 
  ncols = 7, 
  colnames = c("Activity", "10 Minutes or Less", "11-20 Minutes", "21-30 Minutes", 
    "31-40 Minutes", "41-50 Minutes", "More than 50 Minutes")
)
```

### Sitting time yesterday

```{r sitting_table}
x <- select(daily, min_sit)

ea_kable(
  x = x, 
  xlab = "Sitting Time Yesterday", 
  nrows = 1, 
  ncols = 7, 
  colnames = c("Variable", "4 or Fewer Hours", "More than 4 Hours- 6 Hours", 
    "More than 6 Hours- 8 Hours", "More than 8 Hours- 10 Hours", 
    "More than 10 Hours - 12 Hours", "More than 12 Hours")
)
```

Physical Activity Charts
-------------------------------------------------------------------------------

```{r plot_act_yest}
x <- names(select(daily, yest_bike, yest_run, yest_cleaning, yest_none, pedometer, min_walk, min_run, min_act, min_sit))
act <- c("Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Did None of These", "Used Pedometer", "Walked or Biked to Get Somewhere", "Engaged in Physical Fitness", "Engaged in Physical Activity at Work or Home", "Sat")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(act[i], "Yesterday")) +
    theme_bw() +
    if (i > 5) {
      theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
    } else {
      theme()
    }
  print(plot)
  i <- i + 1
}

# Plot steps
ggplot(daily, aes(x = steps)) +
  geom_histogram(binwidth = 1000) +
  scale_x_continuous("") +
  ggtitle("Steps Yesterday") +
  theme_bw()
```









Diet
===============================================================================

Table Row {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Ate any yesterday (Yes / No)

```{r diet_table_1}
x <- select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

ea_kable(
  x = x, 
  xlab = food, 
  nrows = 5, 
  ncols = 3, 
  colnames = c("Food", "No", "Yes")
)
```

### Servings ate yesterday

```{r diet_table_2}
x <- select(daily, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat)

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

ea_kable(
  x = x, 
  xlab = food, 
  nrows = 5, 
  ncols = 7, 
  colnames = c("Food", "0 Servings", "1 Serving", "2 Servings", "3 Servings", "4 Servings", 
    "5 or More Servings")
)
```

Diet Charts
-------------------------------------------------------------------------------

```{r diet_yest}
x <- names(select(daily, any_fruit, any_veg, any_ssb, any_sweets, any_meat, serv_fruit, serv_veg, serv_ssb, serv_sweets, serv_meat))

food <- c("Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat", "Fruit", "Vegetables", "Sugar-Sweetened Beverages", "Deserts and Other Sweets", "Red Meat or Processed Meat")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Ate", food[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```









Medication
===============================================================================

Medication Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Did you take all your medication as prescribed yesterday, and if not, which ones didn't you take?

```{r med_table_1}
x <- select(daily, take_meds, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)

xlab <- c("Take Medications", "Didn't Take Depression / Anxiety / Mood Medication", "Didn't Take Psychiatric Medication", "Didn't Take Asthma / COPD Medication", "Didn't Take Blood Pressure Medication", "Didn't Take Diabetes Medication", "Didn't Take Pain Medication", "Didn't Take Cholesterol Medication", "Didn't Take Antibiotic / Antiviral Medication", "Didn't Take Other Medication")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 10, 
  ncols = 3, 
  colnames = c("Medication", "No", "Yes")
)
```

### Why didn't you take medications?

```{r med_table_2}
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)

xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 6, 
  ncols = 3, 
  colnames = c("Reason", "Wasn't a Reason", "Was a Reason")
)
```

Medication Charts
-------------------------------------------------------------------------------
```{r med_chart, fig.width=12}
# Take Meds (Yes / No)
x <- select(daily, take_meds)
ggplot(x, aes(x = take_meds)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle("Take All Medications as Prescribed Yesterday") +
    theme_bw()

# Which medications not taken
x <- select(daily, medtype_dep, medtype_psy, medtype_ast, medtype_bp, medtype_diab, medtype_pain, medtype_chol, medtype_anti, medtype_other)

xlab <- c("Depression / Anxiety / Mood", "Psychiatric", "Asthma / COPD", "Blood Pressure", "Diabetes", "Pain", "Cholesterol", "Antibiotic / Antiviral", "Other")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Medication Not Taken Yesterday") +
  theme_bw()

# Why medication not taken
x <- select(daily, meds_ran_out, meds_forgot, meds_no_need, meds_side, meds_lost, meds_other)

xlab <- c("Ran out", "Forgot", "Don't Need It", "Side Effects", "Got Lost / Stolen", "Other")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Reason Medication Not Taken Yesterday") +
  theme_bw()
```









Freetime
===============================================================================

Freetime Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### How much free time did you have yesterday?

```{r freetime_table_1}
x <- select(daily, free_time)

xlab <- c("Amount")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 1, 
  ncols = 7, 
  colnames = c("Free time", "2 or fewer hours", "More than 2 hours- 4 hours", 
    "More than 4 hours- 6 hours", "More than 6 hours- 8 hours", "More than 8 hours- 10 hours", 
    "More than 10 hours")
)
```

### What did you do in your free time yesterday?

```{r freetime_table_2}
x <- select(daily, free_tv:free_social, free_none)

xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 17, 
  ncols = 3, 
  colnames = c("Activity", "Didn't Do Yesterday", "Did Yesterday")
)
```

Freetime Charts
-------------------------------------------------------------------------------
```{r freetime_chart, fig.width=12, fig.height=8}
# How much
x <- select(daily, free_time)

xlab <- c("Amount")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle("Amount of Free Time Yesterday") +
    theme_bw() +
    theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  print(plot)
  i <- i + 1
}

# What they did during free time
x <- select(daily, free_tv:free_social, free_none)

xlab <- c("Watched TV", "Played Computer Games", "Went to a Movie", "Surfed the Internet", "Read", "Listened to Music or Played Instrument", "Arts and Crafts", "Cleaned", "Took Care of Pets", "Prayed, Meditated, or Went to Religious Service", "Played a Sport", "Walk or Jog", "Played Cards, Dice, or Board Games", "Went Shopping", "Volunteered", "Socialized", "None of These")

x <- data.frame(sapply(x, table))
x <- gather(x)
x <- x[c(FALSE, TRUE), ]
x$key <- xlab

ggplot(x, aes(x = key, y = value)) +
  geom_bar(stat = "identity") +
  scale_x_discrete("") +
  scale_y_continuous("Number of Responses") +
  ggtitle("Free Time Activity Yesterday") +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
```









Interaction
===============================================================================

Interaction Table {.tabset .tabset-fade}
-------------------------------------------------------------------------------

### Any meaningful interaction yesterday

```{r interaction_table_1}
x <- select(daily, any_talk, any_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 2, 
  ncols = 3, 
  colnames = c("Type", "No", "Yes")
)
```

### Amount of meaningful interaction yesterday

```{r interaction_table_2}
x <- select(daily, min_talk, min_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 2, 
  ncols = 8, 
  colnames = c("Type", "15 or Fewer Minutes", "16-30 Minutes", "31 min- 1 Hour", 
    "More than 1 Hour- 2 Hours", "More than 2 Hours- 3 Hours", "More than 3 Hours- 4 Hours", 
    "More than 4 Hours")
)
```

Interaction Charts
-------------------------------------------------------------------------------
```{r interaction_chart}
# Any interaction
x <- select(daily, any_talk, any_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste(xlab[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
  
# Amount of interaction
x <- select(daily, min_talk, min_group)

xlab <- c("One-On-One Conversations", "Group Interactions")

i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Amount of", xlab[i], "Yesterday")) +
    theme_bw() +
    theme(axis.text.x = element_text(angle = 45, vjust = 0.5))
  print(plot)
  i <- i + 1
}
```









Substances
===============================================================================

Substances Tables
-------------------------------------------------------------------------------

### Substances used yesterday

```{r substance_table}
x <- select(daily, sub_alc, heavy_drink, sub_cig, sub_mar, sub_opi, sub_stim, sub_herb, sub_other, sub_none)

xlab <- c("Alcohol", "5 or More Alcoholic Drinks", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs / Incense", "Another drug", "None")

ea_kable(
  x = x, 
  xlab = xlab, 
  nrows = 9, 
  ncols = 3, 
  colnames = c("Type", "No", "Yes")
)
```

Substances Charts
-------------------------------------------------------------------------------

```{r substance_chart}
x <- names(select(daily, sub_alc, heavy_drink, sub_cig, sub_mar, sub_opi, sub_stim, sub_herb, sub_other, sub_none))
sub <- c("Alcohol", "Tobacco", "Marijuana", "Opiates", "Stimulants", "Herbal Drugs", "Another drug", "No Substances")
i <- 1
for (var in x) {
  plot <- ggplot(daily, aes_string(x = var)) +
    geom_bar() +
    scale_x_discrete("") +
    ggtitle(paste("Participant used", sub[i], "Yesterday")) +
    theme_bw()
  print(plot)
  i <- i + 1
}
```




Session Info
===============================================================================
```{r session_info, echo=FALSE}
sessionInfo()
```